import logging
import time
import os


class HLog(object):
    def __init__(self, name, rq):
        logname = os.getcwd() + "/mainLogs/" + name + rq + '.log'
        self.logger = logging.getLogger(name)
        self.logger.setLevel(logging.INFO)
        self.fh = logging.FileHandler(logname, encoding='utf-8')
        self.fh.setLevel(logging.DEBUG)
        self.formatter = logging.Formatter('%(asctime)s - %(levelname)s - %(threadName)s - %(name)s - %(message)s')
        self.fh.setFormatter(self.formatter)
        self.logger.addHandler(self.fh)

    def info(self, msg):
        self.logger.info(msg)

    def warning(self, msg):
        self.logger.warning(msg)

    def error(self, msg):
        self.logger.error(msg)

    def debug(self, msg):
        self.logger.debug(msg)

    def close(self):
        self.logger.removeHandler(self.fh)
